<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<!--    <link rel="stylesheet" href="../../static/lib/layui-v2.6.3/css/layui.css" media="all">-->
    <link th:href="@{../static/lib/layui-v2.6.3/css/layui.css}" rel="stylesheet">
<!--    <link rel="stylesheet" href="../../css/public.css" media="all">-->
    <link th:href="@{../static/css/public.css}" rel="stylesheet">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<form class="layui-form layuimini-form" lay-filter="editFormFilter">
    <div class="layui-form-item">
        <label class="layui-form-label required">标题名称</label>
        <div class="layui-input-block">
            <input type="text" name="title" lay-verify="required" placeholder="请输入标题名称" value="" class="layui-input">
<!--            <tip>填写自己管理账号的名称。</tip>-->
        </div>
    </div>
<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label required">性别</label>-->
<!--        <div class="layui-input-block">-->
<!--            <input type="radio" name="sex" value="男" title="男" checked="">-->
<!--            <input type="radio" name="sex" value="女" title="女">-->
<!--        </div>-->

    <div class="layui-form-item">
        <label class="layui-form-label required">链接地址</label>
        <div class="layui-input-block">
            <input type="text" name="href" placeholder="请输入链接地址" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图标名称</label>
        <div class="layui-input-block">
            <input type="text" name="icon"  placeholder="请输入图标名称" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">父级菜单</label>
        <div class="layui-input-block">
            <select name="menuId">
                <option value="">请选择父级菜单名称</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序序号</label>
        <div class="layui-input-block">
            <input type="text" name="sort" placeholder="请输入排序序号" value="" class="layui-input">
        </div>
    </div>
<!--    <div class="layui-form-item layui-form-text">-->
<!--        <label class="layui-form-label">备注信息</label>-->
<!--        <div class="layui-input-block">-->
<!--            <textarea name="remark" class="layui-textarea" placeholder="请输入备注信息"></textarea>-->
<!--        </div>-->
<!--    </div>-->

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认更新</button>
        </div>
    </div>
</form>
<script src="../static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<!-- 子页面 (child.html) -->
<script>
    layui.use(['form', 'jquery'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
        $.ajax({
            url: '/menu/getmenupage1', // 你的数据接口地址
            method: 'GET',
            success: function(a) {
                var options = '';
                $.each(a.data, function(index, item){ // 假设 data 是从服务器返回的包含城市数据的数组或对象数组
                    options += '<option value="' + item.menuId + '">' + item.title + '</option>';
                });
                $('select[name="menuId"]').append(options); // 将选项添加到 select 中
                form.render('select'); // 重新渲染 select 以显示新添加的选项
            }
        });
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '添加信息：'
            });
            //     // 发送打卡请求
                $.post('/menu/menuAdd',{ title: data.field.title ,href: data.field.href,icon: data.field.icon,parentId: data.field.menuId,sort: data.field.sort} , function(res){
                    layer.closeAll();
                    if(res.code == 200) {  // 直接判断Boolean返回值
                        layer.msg(res.message+res.data.title , {icon: 1});
                        // layer.close(index);// 关闭弹出层
                    } else {
                        layer.msg(res.message+res.data.title, {icon: 2});
                        // layer.close(index);// 关闭弹出层
                    }
                }).fail(function(){
                    layer.closeAll();
                    layer.msg('请求失败，请重试', {icon: 2});
                    layer.close(index);// 关闭弹出层
                });

            // function () {
            // if(parent.submitFormCallback){
            //     parent.submitFormCallback(data.field);// 关闭弹出层
            //     layer.close(index);// 关闭弹出层
            // } else {
            //     layer.msg('通信异常，请刷新重试', {icon: 2});
            //     layer.close(index);// 关闭弹出层
            // }
            var iframeIndex = parent.layer.getFrameIndex(window.name);
            parent.layer.close(iframeIndex);
             // }

            return false;
        });
        });
</script>
</body>
</html>